package com.freemodbus4j.device.utils;

import com.alinks.modbus.device.storage.Memory;

public final class MemoryUtils {

    public static void write(byte func, int start, byte[] data) {
        switch (func) {
            case 05:
            case 15: {
                Memory.getInstance().writeCoil(start, data);
            } break;
            case 06:
            case 16: {
                Memory.getInstance().writeReg(start, data);
            } break;
            default: return;
        }

    }

    public static byte[] read(byte func, int start, int length) {
        switch (func) {
            case 01:
            case 02: {
                return Memory.getInstance().readCoil(func, start, start + length);
            }
            case 03:
            case 04: {
                return Memory.getInstance().readReg(func, start, start + length);
            }
            default: return new byte[0];
        }
    }
}
